#include<bits/stdc++.h>
using namespace std;
int T;
#define ll long long
vector<ll> A;
const int M=4e5+5;
ll x,pre[M];
ll V[M];
#define mid ((l+r)>>1)
#define ull unsigned long long
struct ST{
	ull lsum[M<<2],rsum[M<<2],sum[M<<2];
	int cnt[M<<2];
	inline void pushup(int now){
		cnt[now]=cnt[now<<1]+cnt[now<<1|1];
		lsum[now]=sum[now<<1]*cnt[now<<1|1]+lsum[now<<1|1]+lsum[now<<1];
		rsum[now]=rsum[now<<1]+rsum[now<<1|1]+sum[now<<1|1]*cnt[now<<1];
		sum[now]=sum[now<<1]+sum[now<<1|1];
		return;
	}
	inline void mdf(int now,int l,int r,int pos,int v){
		if(l==r){
			cnt[now]+=v,sum[now]+=V[l]*v,lsum[now]+=V[l]*v,rsum[now]+=V[l]*v;
			return;
		}
		if(pos<=mid)mdf(now<<1,l,mid,pos,v);
		else mdf(now<<1|1,mid+1,r,pos,v);
		return pushup(now);
	}
	inline ull Kaskmis(int now,int l,int r,int k){
		if(l==r)return k*sum[now];
		if(cnt[now<<1]>=k)return Kaskmis(now<<1,l,mid,k);
		else return sum[now<<1]+Kaskmis(now<<1|1,mid+1,r,k-cnt[now<<1]);
	}
	inline ull Kaskmils(int now,int l,int r,int k){
		if(l==r)return k*sum[now];
		if(cnt[now<<1]>=k)return Kaskmils(now<<1,l,mid,k);
		else return sum[now<<1]*(k-cnt[now<<1])+lsum[now<<1]+Kaskmils(now<<1|1,mid+1,r,k-cnt[now<<1]);
	}
	inline ull Kaskmxs(int now,int l,int r,int k){
		if(l==r)return k*sum[now];
		if(cnt[now<<1|1]>=k)return Kaskmxs(now<<1|1,mid+1,r,k);
		else return sum[now<<1|1]+Kaskmxs(now<<1,l,mid,k-cnt[now<<1|1]);
	}
	inline ull Kaskmxrs(int now,int l,int r,int k){
		if(l==r)return k*sum[now];
		if(cnt[now<<1|1]>=k)return Kaskmxrs(now<<1|1,mid+1,r,k);
		else return sum[now<<1|1]*(k-cnt[now<<1|1])+rsum[now<<1|1]+Kaskmxrs(now<<1,l,mid,k-cnt[now<<1|1]);
	}
}xT;
unordered_set<int> S;
ll P[M];int pvc,idc,q;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline void solve(int C){
	cin>>x;
	// x=rnd()%1000000000000ll;
	P[C]=x;
	// auto tmp=find(A.begin(),A.end(),x);
	// if(tmp!=A.end())A.erase(tmp);
	// else{
		// A.push_back(x);
		// sort(A.begin(),A.end());
	// }
	// if(A.empty())return cout<<"0\n",void();
	// ll lstr=0,ans=0;
	// int siz=A.size();
	// for(int i=0;i<siz;i++)pre[i+1]=A[i]+pre[i];
	// for(int i=1;i<=siz;i++){
		// //pre[i]- pre[siz]-pre[siz-i]
		// if(lstr<pre[siz]-pre[siz-i])ans+=pre[siz]-pre[siz-i]-max(pre[i],lstr),lstr=pre[siz]-pre[siz-i];
	// }
	// cerr<<ans<<'\n';
}
inline void init(){
	for(int i=1;i<=q;i++)V[i]=P[i];
	sort(V+1,V+q+1);
	pvc=unique(V+1,V+q+1)-V-1;
	for(int i=1;i<=q;i++)P[i]=lower_bound(V+1,V+pvc+1,P[i])-V;
	return;
}
inline void solve2(){
	ll ans=0,mip,si;
	ull tp;
	for(T=1;T<=q;T++){
		if(S.count(P[T]))S.erase(P[T]),xT.mdf(1,1,pvc,P[T],-1);
		else S.insert(P[T]),xT.mdf(1,1,pvc,P[T],1);
		si=S.size();
		if(si==1){
			cout<<0<<"\n";
			continue;
		}
		ans=0;
		ans=xT.rsum[1]-xT.lsum[1];
		// cerr<<ans<<" aft\n";
		mip=si/2;
		//1 - si/2 and si/2 - si-1 --- Find 0 pos
		int L=1,R=mip,resl=R+1,resr=R-1,mi;
		while(L<=R){
			mi=(L+R)>>1;
			if(xT.Kaskmxs(1,1,pvc,mi)>=xT.Kaskmis(1,1,pvc,mi+1))resl=mi,R=mi-1;
			else L=mi+1;
		}
		L=si/2,R=si-1;
		while(L<=R){
			mi=(L+R)>>1;
			if(xT.Kaskmxs(1,1,pvc,mi)>=xT.Kaskmis(1,1,pvc,mi+1))resr=mi,L=mi+1;
			else R=mi-1;
		}
		if(resl<=resr){
			tp=xT.Kaskmxrs(1,1,pvc,resr)-xT.Kaskmxrs(1,1,pvc,resl-1);
			tp-=xT.Kaskmils(1,1,pvc,resr+1)-xT.Kaskmils(1,1,pvc,resl);
		}else tp=0;
		ans-=tp;
		cout<<ans<<'\n';
	}
	return;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	cin>>T;q=T;
	while(T--)solve(++idc);
	init();
	solve2();
	return 0;
}